<?php
class NewsType extends Base
{
    protected function getPrimaryKey()
    {
        return "newsTypeId";
    }

    public function loadById($id)
    {
        // TODO: Implement loadById() method.
    }

    protected function getTableName()
    {
        return "news_type";
    }


    public function find()
    {
        $sql = "select * from " . $this->getTableName();
        return $this->_db->getall($sql);
    }

    protected function competeRecord($post)
    {
        $record = array(
            "title" => $post['title'],
            "createDate" => date("Y-m-d H:i:s")
        );
        return $record;
    }

    public function delete($id)
    {
        try {
            $news_sql = "delete from news where type=" . $id;
            $comment_delete_sql = "delete from comment where type = 'NEWS' and operatorId in (select newsId from news where type=" . $id . ")";
            $newstype_delete_sql = "delete from " . $this->getTableName() . " where " . $this->getPrimaryKey() . "=" . $id;
            $this->_db->beginTransaction();
            $this->_db->query($news_sql);
            $this->_db->query($comment_delete_sql);
            $this->_db->query($newstype_delete_sql);
            $this->_db->commit();
        } catch (Exception $e) {
            $this->_db->rollBack();
            echo $e->getMessage();
        }
    }
}

?>